package fr.vincent7894.feedroid.feed.task;

import java.util.Collection;

import fr.vincent7894.feedroid.feed.pojo.Feed;
import fr.vincent7894.feedroid.utils.Logger;
import android.app.ProgressDialog;

public abstract class AbstractProgressDialogFeedTask extends AbstractFeedTask<ProgressDialog> {
	
	private static final String DIALOG_MSG = "Récupération et traitement du flux ...";
	
	public AbstractProgressDialogFeedTask(ProgressDialog view) {
		super(view);
	}

	@Override
	protected void onCancelled() {
		this.getMediator().getWidget().cancel();
	}
	
	@Override
	protected void onProgressUpdate(Integer... values) {
		if(values != null && values.length > 0) {
			Integer value = values[0];
			this.getMediator().getWidget().setProgress(value);	
		}
		else {
			Logger.info("Values is null or empty");
		}
	}
	
	@Override
	protected void onPostExecute(Collection<Feed> result) {
		this.getMediator().getWidget().dismiss();
	}
	
	@Override
	protected void onPreExecute() {
		this.getMediator().getWidget().setIndeterminate(true);
		this.getMediator().getWidget().setCancelable(true);
		this.getMediator().getWidget().setTitle("Progress feed task");
		this.getMediator().getWidget().setMessage(DIALOG_MSG);
		this.getMediator().getWidget().setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		this.getMediator().getWidget().show();
	}
}
